home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / Prog / A / AxoCalculator Package / AxoCalculator AutoLoad / Unit Conversions < prev   
Encoding:
Text File  |  1993-01-24  |  3.4 KB  |  134 lines  |  [TEXT/AxoC]

  1. LocalLanguage Pascal
  2. {-------------------------------------------------
  3. This document contains a unit conversion function.
  4.   
  5.     function cnvt (x, unit1, unit2) : Real
  6.  
  7. •  To load this function choose "Select All" under 
  8.     the "Edit" menu, then press "enter". 
  9.  
  10. For example, 
  11.  
  12. cnvt (10, inch, mm) 
  13.  
  14. returns 254  (i.e. 10 inches equals 254 mm). 
  15.  
  16. Units supported
  17. Length
  18.   mm, cm, meter, km, 
  19.   inch, foot, yard, mile, furlong (fur), nautical mile (nMile)
  20.  
  21. Speed
  22.   km per hour (kmph), meters per second (mps),
  23.   miles per hour (mph), nautical miles per hour (knot)
  24.  
  25. Mass
  26.   gram, kilogram (kg), tonne, 
  27.   ounce (oz), pound (lb), stone, ton
  28.  
  29. Volume (Fluids)
  30.   mililitre (ml), litre, megaLitre,
  31.   fluid ounze (floz), pint (pt), US gallon (USgal or gal), 
  32.   British gallon (BrGal), acre foot (acreFt)
  33.  
  34. Pressure
  35.   kilopascal (kPa), 
  36.   pound per square inch (psi), atmosphere (atm)
  37.  
  38. Temperature
  39.   degrees centigrade (degC), degrees Kelvin (degK),
  40.   degrees Farenheit (degF)
  41.  
  42.  
  43. •  To add a unit to the list, declare it as a global 
  44.     array with 2 elements. The first element receives
  45.     the conversion factor relative to a standard unit.
  46.     For example, length units are defined relative to 
  47.     1 meter and speed units relative to 1 meter per second. 
  48.     The second element receives the unit type.
  49.     This is 1 for length units, 2 for speed units, etc.
  50.     The unit type is used in "cnvt" for checking whether
  51.     the requested conversion is a legal one. 
  52. --------------------------------------------------}
  53.  
  54. {• Global Declaration of supported units •}
  55. Var
  56. {• Length •}
  57.     mm, cm, meter, km, inch, foot, yard, mile, fur, nauMile : Array[2]
  58. {• Speed •}
  59.     mph, knot, kmph, mps : Array[2]
  60. {• Mass •}
  61.     gram, kg, tonne, oz, lb, stone, ton : Array[2]
  62. {• Fluid volume •}
  63.     ml, litre, megaLitre, floz, pt, gal, USGal, BrGal, acreFt : Array[2]
  64. {• Pressure •}
  65.     kPa, psi, atm : Array[2]
  66. {• Temperature •}
  67.     degC, degK, degF : Array[3]
  68.  
  69. {• Conversion function •}
  70. function cnvt (x, unit1, unit2) : Real
  71. begin
  72. {• Perform conversion •}
  73.     if unit1[2] = unit2[2] then
  74.     begin
  75.         if unit1[2] <> 6 then
  76.         {• Normal conversion •}
  77.             cnvt = x * unit1[1] / unit2[1]
  78.         else
  79.         {• Temperature conversion •}
  80.             cnvt = (x + unit1[3]) * unit1[1] / unit2[1] - unit2[3]
  81.     end
  82.     else
  83.     begin
  84.     {• Different units •}
  85.         write ('The two unit types are not compatible')
  86.         cnvt = 0
  87.     end
  88. end
  89.  
  90. {• Set conversion factors •}
  91.     mm[1] = 0.001;         mm[2] = 1
  92.     cm[1] = 0.01;            cm[2] = 1
  93.     meter[1] = 1;            meter[2] = 1
  94.     km[1] = 1000;            km[2] = 1
  95.     inch[1] = 0.0254;        inch[2] = 1
  96.     foot[1] = 0.305;        foot[2] = 1
  97.     yard[1] = 0.914;        yard[2] = 1
  98.     mile[1] = 1610;        mile[2] = 1
  99.     nauMile[1] = 1852;    nauMile[2] = 1
  100.     fur[1] = 201;            fur[2] = 1
  101.     
  102.     mps[1] = 1;                mps[2] = 2
  103.     mph[1] = 0.44722;    mph[2] = 2
  104.     knot[1] = 0.51444;    knot[2] = 2
  105.     kmph[1] = 0.27778;    kmph[2] = 2
  106.     
  107.     gram[1] = 1;            gram[2] = 3
  108.     kg[1] = 1000;            kg[2] = 3
  109.     tonne[1] = 1.0e6;        tonne[2] = 3
  110.     oz[1] = 28.3;            oz[2] = 3
  111.     lb[1] = 454;                lb[2] = 3
  112.     stone[1] = 6350;        stone[2] = 3
  113.     ton[1] = 1.02e6;        ton[2] = 3
  114.     
  115.     litre[1] = 1;            litre[2] = 4
  116.     ml[1] = 0.01;            ml[2] = 4
  117.     megaLitre[1] = 1.0e6;    megaLitre[2] = 4
  118.     floz[1] = 0.0284;        floz[2] = 4
  119.     pt[1] = 0.568;            pt[2] = 4
  120.     gal[1] = 3.7853;        gal[2] = 4
  121.     USGal[1] = 3.7853;    USGal[2] = 4
  122.     BrGal[1] = 4.54596;    BrGal[2] = 4
  123.     acreFt[1] = 1.23e6;    acreFt[2] = 4
  124.     
  125.     kPa[1] = 1;                kPa[2] = 5
  126.     psi[1] = 6.89;            psi[2] = 5
  127.     atm[1] = 101;            atm[2] = 5
  128.     
  129.     degK[1] = 1;            degK[2] = 6;      degK[3] = 0
  130.     degC[1] = 1;            degC[2] = 6;      degC[3] = 273.12
  131.     degF[1] = 0.555556;    degF[2] = 6;      degF[3] = 459.61
  132.     
  133.  
  134.